<?php

namespace Sm\AssBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class SrtType extends AbstractType {

    public function buildForm(FormBuilderInterface $builder, array $options) {
        
        $builder->add('style', 'entity', array(
            'class' => 'SmAssBundle:Style',
            'attr' => array(
                'class' => "srtStyle"
            ),
            'query_builder' => 
                function(\Sm\AssBundle\Entity\StyleRepository $er) use ($options){
                    return $er->createQueryBuilder('Style')
                    ->leftJoin('Style.ass', 'ass')
                    ->where('ass.id = :param')
                    ->setParameter('param', $options['attr']['ass-id']);
                }
            )
        );
        
        $builder->add('start', 'text', array(
            'attr' => array(
                'class' => "srtStart"
            )
        ));
        
        $builder->add('end', 'text', array(
            'attr' => array(
                'class' => "srtEnd"
            )
        ));
        
        $builder->add('content', 'textarea', array(
            'label' => false,
            'attr' => array(
                'class' => 'srtContent', 
                'style' => 'width:100%'
            )
        ));
        
        $builder->add('save', 'submit', array(
            'label' => 'Enregistrer'
        ));
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver) {
        $resolver->setDefaults(array(
            'data_class' => 'Sm\AssBundle\Entity\Srt',
        ));
    }

    function getName() {
        return 'srt';
    }

}